$(function(){
	$('#leftMenu-trash').addClass('active');
});
$(document).ready(function() {
	var tableElement;
	var vp_w = $(window).width();
	var vp_h = $(window).height();
	var table;
	if (vp_w >= 768) {
		tableElement = $('#dataTableTrash').dataTable({
			"sDom" : '<"top">rt<"bottom"p><"clear">',
			"aoColumns" : [ {
				"sWidth" : "45%"
			}, {
				"sWidth" : "25%",
				"visible" : false
			}, {
				"sWidth" : "25%"
			}, {
				"sWidth" : "20%"
			}, {
				"sWidth" : "10%"
			}, {
				"sWidth" : "0%",
				"visible" : false
			}, {
				"sWidth" : "0%",
				"visible" : false
			} ],
			"sScrollY" : vp_h - 350,
			"iDisplayLength" : 15,
			"bScrollCollapse" : true,
			"aaSorting" : [],
			"order" : [ [ 2, "asc" ] ],
			"aoColumnDefs" : [ {
				"bSortable" : false,
				"aTargets" : [ "no-sort" ]
			} ],
			"pagingType" : "full_numbers"
		});
	} else {
		tableElement = $('#dataTableTrash').dataTable({
			"sDom" : '<"top">rt<"bottom"p><"clear">',
			"aoColumns" : [ {
				"sWidth" : "70%"
			}, {
				"sWidth" : "25%",
				"visible" : false
			}, {
				"sWidth" : "15%"
			}, {
				"sWidth" : "15%",
				"visible" : false
			}, {
				"sWidth" : "15%"
			}, {
				"sWidth" : "0%",
				"visible" : false
			}, {
				"sWidth" : "0%",
				"visible" : false
			} ],
			"sScrollY" : "550px",
			"iDisplayLength" : 15,
			"bScrollCollapse" : true,
			"aaSorting" : [],
			"aoColumnDefs" : [ {
				"bSortable" : false,
				"aTargets" : [ "no-sort" ]
			} ],
			"pagingType" : "full_numbers"
		});
	}
	$('#dataTableTrash tbody').on( 'click', 'tr', function () {
		if($(this).find('td:eq(0)').text() != "This folder is empty"){
			if ($(this).hasClass('selected')) {
				$(this).removeClass('selected');
				$(this).find('td:eq(4) button').addClass('hidden-share');
				$('#btn-restoreDocument').addClass('hidden');
		    	$('#btn-deleteDocument').addClass('hidden');
		    	$('#documentNameSelect').val('');
		    	$('#documentPathSelect').val('');
		    	$('#documentTypeSelect').val('');
		    	$('#documentEmailSelect').val('');
		    }
		    else {
		    	tableElement.$('tr.selected').removeClass('selected');
		    	$(this).addClass('selected');
		    	$('.btn-share button').addClass('hidden-share');
		    	$(this).find('td:eq(4) button').removeClass('hidden-share');
		    	$('#btn-restoreDocument').removeClass('hidden');
		    	$('#btn-deleteDocument').removeClass('hidden');
		    	$('#documentNameSelect').val($(this).find('td:eq(0)').text().trim());
		    	$('#documentPathSelect').val(tableElement.fnGetData(tableElement.fnGetPosition(this))[1]);
		    	$('#documentTypeSelect').val(tableElement.fnGetData(tableElement.fnGetPosition(this))[5]);
		    	$('#documentEmailSelect').val(tableElement.fnGetData(tableElement.fnGetPosition(this))[6]);
			}
		}
	});
});